package com.ciei.dpagm.shiro;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.mgt.DefaultWebSessionStorageEvaluator;
import org.apache.shiro.web.subject.WebSubject;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
* @author yw
* @date 2023/12/11
*/
@Component
public class ShiroSessionStorge extends DefaultWebSessionStorageEvaluator {

    @Override
    public boolean isSessionStorageEnabled(Subject subject) {
        if(subject instanceof WebSubject){
            HttpServletRequest request = (HttpServletRequest) ((WebSubject) subject).getServletRequest();
            String token = request.getHeader("authorization");
            if(StringUtils.isNotBlank(token)) {
                return false;
            }
        }
        return super.isSessionStorageEnabled(subject);
    }
}
